import request from "@/utils/request";
import type { Carousel } from "@/types";

interface CreateCarouselDto {
  title: string;
  subTitle: string;
  description?: string;
  imageUrl?: string;
  backgroundColor?: string;
  linkUrl?: string;
  status: 'active' | 'inactive';
  order: number;
}

interface UpdateCarouselDto extends Partial<CreateCarouselDto> {}

interface PaginationDto {
  page: number;
  limit: number;
}

interface PaginatedResponseDto<T> {
  items: T[];
  total: number;
}

// 获取所有走马灯
export async function getAllCarousels() {
  return (
    await request<Carousel[]>({
      url: "/carousels",
      method: "get",
    })
  ).data;
}

// 获取分页走马灯
export async function getPaginatedCarousels(params: PaginationDto) {
  return (
    await request<PaginatedResponseDto<Carousel>>({
      url: "/carousels/paginated",
      method: "get",
      params,
    })
  );
}

// 获取所有激活状态的走马灯
export async function getActiveCarousels() {
  return (
    await request<Carousel[]>({
      url: "/carousels/active",
      method: "get",
    })
  ).data;
}

// 获取分页激活状态的走马灯
export async function getActivePaginatedCarousels(params: PaginationDto) {
  return (
    await request<PaginatedResponseDto<Carousel>>({
      url: "/carousels/active/paginated",
      method: "get",
      params,
    })
  ).data;
}

// 根据ID获取单个走马灯
export async function getCarouselById(id: number) {
  return (
    await request<Carousel>({
      url: `/carousels/${id}`,
      method: "get",
    })
  ).data;
}

// 创建新走马灯
export async function createCarousel(data: CreateCarouselDto) {
  return (
    await request<Carousel>({
      url: "/carousels",
      method: "post",
      data,
    })
  ).data;
}

// 更新走马灯
export async function updateCarousel(id: number, data: UpdateCarouselDto) {
  return (
    await request<Carousel>({
      url: `/carousels/${id}`,
      method: "patch",
      data,
    })
  ).data;
}

// 删除走马灯
export async function deleteCarousel(id: number) {
  return request({
    url: `/carousels/${id}`,
    method: "delete",
  });
} 